package cn.big.bigd.biocode.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.security.core.GrantedAuthority;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zoud on 2016/10/14.
 */
@Entity
@Table(name="roles")
public class Role implements GrantedAuthority {

    public static final Role ADMIN = new Role(1, "ADMIN");

    public static final Role CURATOR = new Role(2, "CURATOR");

    public static final Role DBA = new Role(3, "DBA");

    public static final Role USER = new Role(4,"USER");

    @Id
    private int id;

    @Column(length = 10)
    private String name;
    @JsonIgnore
    @ManyToMany(mappedBy = "roleList")
    private List<User> userList = new ArrayList<>();

    public Role(){}

    public Role(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<User> getUserList() {
        return userList;
    }

    public void setUserList(List<User> userList) {
        this.userList = userList;
    }

    @Override
    public String getAuthority() {
        return name;
    }

    @Override
    public String toString() {
        return "Role{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
